package com.zq.structure.flyweight;

import org.omg.PortableInterceptor.INACTIVE;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public final class CharacterFactory {

    private final Map<String, Character> characterMap = new HashMap<>();

    public static CharacterFactory getInstance() {
        return InnerSingletonHelper.INSTANCE;
    }

    private static class InnerSingletonHelper {
        private static final CharacterFactory INSTANCE = new CharacterFactory();
    }

    private CharacterFactory() {
        characterMap.put("A", new CharacterA());
        characterMap.put("B", new CharacterB());
    }

    public Character getCharacter(String key) {
        return characterMap.get(Objects.requireNonNull(key));
    }
}
